<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    *{padding: 0; margin: 0; list-style-type: none;}
    .cont{ width: 150px; height: 150px; position: relative;background-color: red;}
</style>
<body>
    <div class="cont"></div>
    <script>
        let cont = document.querySelector('.cont');
        let pageX = 0, pageY = 0;
        let clientX = 0 , clientY = 0;
        cont.onmousedown = function(e){
            console.log(e);
            pageX = e.offsetX;
            pageY = e.offsetY;
            window.onmousemove = function(e){
                let x = (e.clientX - pageX) + 'px';
                let y = (e.clientY - pageY) + 'px';
                cont.style.left = x;
                cont.style.top = y;
            }
        }

        window.onmouseup = function(){
            window.onmousemove = null;
        }

    </script>
</body>
</html>